package com.iwhalecloud.citybrain.flow.platform.manager.infrastructure.web;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.iwhalecloud.citybrain.flow.platform.manager.application.event.EventResponse;
import com.iwhalecloud.citybrain.flow.platform.manager.common.client.HttpTaskQueryInfoDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author: liyang
 * @date: 2021/10/18 19:59
 */
@RestController
@RequestMapping("/test")
@Slf4j
public class FlowTestController {

    @PostMapping("/getFunctionResults")
    public List<Map> getCustomFunctionResults( @RequestBody JSONObject json) {
        List<Map> list = new ArrayList<>();
        list.add(new HashMap() {
            {
                put("id", 335241);
                put("name", "李四");
                put("userId", "17801130176");
                put("applyInitiator", "17801135341");
                put("companyId", "335241");
            }
        });
        System.out.println("入参：" +json.toJSONString());
//        list.add(new HashMap() {
//            {
//                put("userId", json.getString("applyInitiator"));
//            }
//        });
//        list.add(new HashMap() {
//            {
//                put("userId", json.getString("parAssignee"));
//            }
//        });
        return list;
    }

    @GetMapping("/getFormUrl")
    public Map<String, Object> getFormUrl() {
        Map<String, Object> param = new HashMap();
        param.put("formUrl", "http://www.baidu.com");
        param.put("formName", "本地测试外置表单");

        List<Map> list = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            Map field = new HashMap();
            field.put("code", "TEST-CODE-" + i);
            field.put("name", "TEST-NAME-" + i);
            field.put("type", i / 2);
            list.add(field);
        }
        param.put("properties", list);
        return param;
    }

    @PostMapping("/testEventRespon")
    public EventResponse getEventRespon(@RequestBody HttpTaskQueryInfoDto taskQueryDto) {
        EventResponse eventResponse = new EventResponse();
        eventResponse.setMsg("test");
        List<String> stringList = new ArrayList<>();
        stringList.add("a");
        stringList.add("b");
        stringList.add("c");
        stringList.add("x");
        stringList.add("y");
        stringList.add("z");
        eventResponse.setDatas(stringList);
        eventResponse.setSuccess(true);

        //eventResponse.setSuccess(true);
        log.error("testEventRespon result:" + JSON.toJSONString(eventResponse));
        return eventResponse;
    }


    @PostMapping("/testTakeBack")
    public EventResponse testTakeBack(@RequestBody JSONObject jsonObject) {
        EventResponse eventResponse = new EventResponse();
        eventResponse.setMsg("test");
        jsonObject.put("testTakeBack","测试拿回预处理后处理成功");
        eventResponse.setSuccess(true);
        eventResponse.setDatas(jsonObject);
        return eventResponse;
    }

}
